/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package su.samlib.informer.database.model;

import java.io.Serializable;
import java.util.Date;
import java.util.List;
import javax.persistence.*;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;

/**
 *
 * @author rikland
 */
@Entity
@Table(name = "author")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "Author.findAll", query = "SELECT a FROM Author a"),
    @NamedQuery(name = "Author.findByAuthorId", query = "SELECT a FROM Author a WHERE a.authorId = :authorId"),
    @NamedQuery(name = "Author.findByAuthorFio", query = "SELECT a FROM Author a WHERE a.authorFio = :authorFio"),
    @NamedQuery(name = "Author.findByAuthorUpdateDate", query = "SELECT a FROM Author a WHERE a.authorUpdateDate = :authorUpdateDate"),
    @NamedQuery(name = "Author.findByAuthorUri", query = "SELECT a FROM Author a WHERE a.authorUri = :authorUri")})
public class Author implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @Basic(optional = false)
    @Column(name = "author_id", nullable = false)
//    @GeneratedValue(generator="author_author_id_seq")
//    @SequenceGenerator(name="author_author_id_seq",sequenceName="author_author_id_seq",allocationSize=1)
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Integer authorId;
    @Column(name = "author_fio", length = 250)
    private String authorFio;
    @Column(name = "author_update_date")
    @Temporal(TemporalType.DATE)
    private Date authorUpdateDate;
    @Basic(optional = false)
    @Column(name = "author_uri", nullable = false, length = 50)
    private String authorUri;
    @JoinColumn(name = "library_id", referencedColumnName = "library_id", nullable = false)
    @ManyToOne(optional = false)
    private Library libraryId;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "author")
    private List<UserAuthors> userAuthorsList;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "authorId")
    private List<Book> bookList;

    public Author() {
    }

    public Author(Integer authorId) {
        this.authorId = authorId;
    }

    public Author(Integer authorId, String authorUri) {
        this.authorId = authorId;
        this.authorUri = authorUri;
    }

    public Integer getAuthorId() {
        return authorId;
    }

    public void setAuthorId(Integer authorId) {
        this.authorId = authorId;
    }

    public String getAuthorFio() {
        return authorFio;
    }

    public void setAuthorFio(String authorFio) {
        this.authorFio = authorFio;
    }

    public Date getAuthorUpdateDate() {
        return authorUpdateDate;
    }

    public void setAuthorUpdateDate(Date authorUpdateDate) {
        this.authorUpdateDate = authorUpdateDate;
    }

    public String getAuthorUri() {
        return authorUri;
    }

    public void setAuthorUri(String authorUri) {
        this.authorUri = authorUri;
    }

    public Library getLibraryId() {
        return libraryId;
    }

    public void setLibraryId(Library libraryId) {
        this.libraryId = libraryId;
    }

    @XmlTransient
    public List<UserAuthors> getUserAuthorsList() {
        return userAuthorsList;
    }

    public void setUserAuthorsList(List<UserAuthors> userAuthorsList) {
        this.userAuthorsList = userAuthorsList;
    }

    @XmlTransient
    public List<Book> getBookList() {
        return bookList;
    }

    public void setBookList(List<Book> bookList) {
        this.bookList = bookList;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (authorId != null ? authorId.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Author)) {
            return false;
        }
        Author other = (Author) object;
        if ((this.authorId == null && other.authorId != null) || (this.authorId != null && !this.authorId.equals(other.authorId))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "su.samlib.informer.database.model.Author[ authorId=" + authorId + " ]";
    }
    
}
